package com.atguigu.lease.model.result;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
@Schema(description = "统一响应类")
public class Response<T> {
    @Schema(description = "状态码：200表示成功,其他表示失败")
    private Integer code;
    @Schema(description = "状态码的描述")
    private String message;
    @Schema(description = "响应数据")
    private T data;

    public static <T> Response<T>  build(Integer code , String msg , T data){
        Response<T> response = new Response<>();
        response.setCode(code);
        response.setMessage(msg);
        response.setData(data);
        return response;
    }
    public static <T> Response<T> ok(T data){
        return build(200 , "SUCCESS" , data);
    }

    public static <T> Response<T> fail(){
        return build(-1 , "ERROR" , null);
    }
    public static <T> Response<T> fail(Integer code , String msg){
        return build(code , msg , null);
    }
    //修改成员属性值的链式调用的方法
    public Response message(String msg){
        this.message = msg;
        return this;
    }
    public Response code(Integer code){
        this.code = code;
        return this;
    }
}
